#################
# Appendix      #    
# Figure 12     #
#################


##################screen setting############

windows(30,25)
par(mfrow=c(2,3)) 



##################TSCA:USA############################
#load data
tb_usa_mpcomparison<-read.csv("tb_usa_mpcomparison.csv")
attach(tb_usa_comparison)

#change colnames
summary(tb_usa_mpcomparison)
df_tsclust1<-tb_usa_mpcomparison[,c(-1,-2)]
colnames(df_tsclust1)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                       "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust1 <- diss(df_tsclust1, "DTWARP")
d_dtw_clust1
# hclust with complete method
h1 <- hclust(d_dtw_clust1)

plot(h1,main="TC Dendrogram US" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:UK############################
#load data
tb_uk_mpcomparison<-read.csv("tb_uk_mpcomparison.csv")
attach(tb_uk_comparison)

#change colnames
summary(tb_uk_mpcomparison)
df_tsclust2<-tb_uk_mpcomparison[,c(-1,-2)]
colnames(df_tsclust2)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust2 <- diss(df_tsclust2, "DTWARP")
d_dtw_clust2
# hclust with complete method
h2 <- hclust(d_dtw_clust2)

plot(h2,main="TC Dendrogram UK" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:JAPAN############################
#load data
tb_jp_mpcomparison<-read.csv("tb_jp_mcomparison.csv")
attach(tb_jp_mpcomparison)

#change colnames
summary(tb_jp_mpcomparison)
df_tsclust3<-tb_jp_mpcomparison[,c(-1,-2)]
colnames(df_tsclust3)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust3 <- diss(df_tsclust3, "DTWARP")
d_dtw_clust3
# hclust with complete method
h3 <- hclust(d_dtw_clust3)
plot(h3,main="TC Dendrogram JAPAN" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:GERMANY############################
#load data
tb_german_mpcomparison<-read.csv("tb_german_mpcomparison.csv")
attach(tb_german_mpcomparison)

#change colnames
summary(tb_german_mpcomparison)
df_tsclust4<-tb_german_mpcomparison[,c(-1,-2)]
colnames(df_tsclust4)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust4 <- diss(df_tsclust4, "DTWARP")
d_dtw_clust4
# hclust with complete method
h4 <- hclust(d_dtw_clust4)
plot(h4,main="TC Dendrogram GERMANY" ,xlab="cluster(complete method)",hang = -1)


##################TSCA:DENMARK############################
#load data
tb_denmark_mpcomparison<-read.csv("tb_denmark_mpcomparison.csv")
attach(tb_denmark_mpcomparison)

#change colnames
summary(tb_denmark_mpcomparison)
df_tsclust5<-tb_denmark_mpcomparison[,c(-1,-2)]
colnames(df_tsclust5)=c("DRA","CONVENTIONAL","LT-nested","LT-simple","LT-withIndep",
                        "NP-nested","NP-simple","NP-withIndep")


# calculating dtwarp distance
d_dtw_clust5 <- diss(na.omit(df_tsclust5), "DTWARP")
d_dtw_clust5
# hclust with complete method
h5 <- hclust(d_dtw_clust5)
plot(h5,main="TC Dendrogram DENMARK" ,xlab="cluster(complete method)",hang = -1)

